#!/bin/bash
# 批量改后缀名
mod_dir="$1"
old_suf="$2"
new_suf="$3"

if [ $# -ne 3 ] || ! [ -d "${mod_dir}" ]
then
    echo "WARN:ERROR parameters"
    exit
fi

function fn_chg_suf()
{
    local fname="$1"
    if  [ -f "${fname}" ] 
    then
        mv -v "${fname}" "${fname%.*}"."${new_suf}" 
    else
        echo "can not find file ${fname}."
    fi
}

mod_flist=(`find ${mod_dir} -type f -name "*.${old_suf}" -print0 |xargs -0`)
for ((i=0;i<${#mod_flist[*]};i++))
do
    fn_chg_suf "${mod_flist[$i]}"
done
